import { baseUrlApi, requestClient, type Result } from '#/api/request';

/** 获取系统邮箱配置 */
export const getMaliConfig = () => {
  return requestClient.get<Result>(baseUrlApi('/admin/mail/config'));
};

/** 更新系统邮箱配置 */
export const putMaliConfig = (data: {
  from: string;
  from_name: string;
  host: string;
  password: string;
  port: string;
  smtp_secure?: string;
  username: string;
}) => {
  return requestClient.put<Result>(baseUrlApi('/admin/mail/config'), data);
};

/** 测试系统邮箱配置 */
export const postMaliTest = (data: {
  content: string;
  subject: string;
  to: string;
}) => {
  return requestClient.post<Result>(baseUrlApi('/admin/mail/test'), data);
};

/** 获取邮箱数字验证码模板配置 */
export const getMaliTemplate = (params: { template_key: string }) => {
  return requestClient.get<Result>(baseUrlApi('/admin/mail/template'), {
    params,
  });
};

/** 更新邮箱数字验证码模板 */
export const putMaliTemplate = (data: {
  subject: string;
  template: string;
  template_key: string;
}) => {
  return requestClient.put<Result>(baseUrlApi('/admin/mail/template'), data);
};
